<template>
	<view class="comments-box">
		<view class="comments-header">
			<view class="comments-header-logo">
				<image :src="comments.author.avatar" mode="aspectFill"></image>
			</view>
			<view class="comments-header-info">
				<view v-if="!reply" class="info-author-name">
				{{comments.author.author_name}}
				</view>
				<view v-else class="info-author-name" >
				 
						{{comments.author.author_name}}
						<uni-icons class="reply_icon" type="redo-filled" color="#F07373"></uni-icons>
						<text class="reply_text">{{comments.to}}</text>
					 					
				</view>
				<view class="info-author-createtime">
					{{comments.create_time}}
				</view>
			</view>
		</view>
		<view class="comments-content">
			<view>{{comments.comment_content}}</view>
			<view class="comments-info">
				<view class="comments-button" @click="commentsReply({comments:comments,is_reply:reply})">回复</view>
			</view>
			<view class="comments-reply" v-for="item in comments.replys" :key="item.comment_id">
				<comments-box :reply="true" :comments="item" @reply="commentsReply"></comments-box>
			</view>
		</view>
	</view>
</template>

<script>
	import commentsBox from '@/components/comments-box/comments-box.vue'
	
	export default {
		name:"comments-box",
		props:{
			comments:{
				type:Object,
				default(){
					return {}
				}
			},
			reply:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				
			};
		},
		methods:{
			commentsReply(comment){
				//为了区分事主回复还是子回复  false是主回复true是子回复
				if(comment.is_reply){
					comment.comments.reply_id=comment.comments.comment_id   
					comment.comments.comment_id=this.comments.comment_id 
				} 
				 
				//console.log(comment)
				this.$emit('reply',comment)
			}
		}
	}
</script>

<style lang="scss">
	.comments-box{
		margin: 15px 0;
		.comments-header{
			display: flex;
			.comments-header-logo{
				flex-shrink: 0;
				width: 30px;
				height:30px;
				overflow: hidden;
				border-radius: 5px;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.comments-header-info{
				display: flex;
				flex-direction:column;
				padding-left: 15px;
				font-size: 12px;
				color: #999;
				line-height: 1;
				.info-author-name{
					margin-bottom: 5px;
					font-size: 14px;
					color: #333;
					.reply_icon{
						margin:0 10px;
					}
					.reply_text{
						font-weight: bold;
						color: #000;
				
					}
				}
			}
		}
		.comments-content{
			margin-top: 10px;
			font-size: 14px;
			color: #000;
			.comments-info{
				margin-top: 10px ;
				display: flex;
				.comments-button{
					padding: 2px 10px;
					font-size: 12px;
					color: #999;
					border: 1px #ccc solid;
					border-radius: 20px;
				}
			}
			.comments-reply{
				display: flex;
				margin: 15px 0;
				padding: 0 15px;
				border: 1px #eee solid;
			}
		}
	}
</style>
